package com.threeti.mecool.core.domain.model.project;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

@Entity
@Table(name = "DM_PROJECT_STORE_ST")
public class ProjectStoreSellingTarget {
    private Long id;
    private Integer version;
    private ProjectStore projectStore;
    private Set<ProjectStoreSellingTargetValue> values = new HashSet<ProjectStoreSellingTargetValue>();

    public void add(int year, int month, int summary) {
        ProjectStoreSellingTargetValue projectStoreSellingTargetValue = new ProjectStoreSellingTargetValue();
        values.add(projectStoreSellingTargetValue);
        projectStoreSellingTargetValue.setSellingTarget(this);
        projectStoreSellingTargetValue.setYearMonth(year * 100 + month);
        projectStoreSellingTargetValue.setSummary(summary);
    }

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    public Long getId() {
        return id;
    }

    @Version
    public Integer getVersion() {
        return version;
    }

    @OneToOne
    public ProjectStore getProjectStore() {
        return projectStore;
    }

    @OneToMany(mappedBy = "sellingTarget", cascade = CascadeType.ALL)
    public Set<ProjectStoreSellingTargetValue> getValues() {
        return values;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public void setVersion(Integer version) {
        this.version = version;
    }

    public void setProjectStore(ProjectStore projectStore) {
        this.projectStore = projectStore;
    }

    public void setValues(Set<ProjectStoreSellingTargetValue> values) {
        this.values = values;
    }
}
